﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Data;
using ESOL.Common.Entity;
using System.IO;

namespace ESOL.Services
{
    [ServiceContract]
    public interface IBptService
    {
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool TestConnect();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptMaintainApp GetBptMaintainAppByKey(string bptAppId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddBptMaintainApp(BptMaintainApp bptMaintainApp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateBptMaintainApp(BptMaintainApp bptMaintainApp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptAppEntity GetBptAppByKey(string bptAppId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBptAppByCondition(BptQueryCondition queryCondition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptTaskEntity GetBptTaskByKey(string bptTaskId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptMaintainTask GetBptMaintainTaskByKey(string bptTaskId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBptTaskByCondition(int pageIndex, int pageCount, string condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool AddBptApp(BptAppEntity bptApp);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateBptApp(BptAppEntity bptApp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DelBptApp(BptAppEntity bptApp);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool CreateBptAppWf(BptAppEntity bptApp);



        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateBptTask(BptTaskEntity bptTask);
        


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptTaskEntity BptAppToTask(BptMaintainApp bptMaintainApp);

        /// <summary>
        /// 技术制图任务工作流完成
        /// 技术申请状态：完成
        /// 同步销售申请明细表产品ID
        /// 同步上传图纸路径到产品表
        /// 生成生产计划
        /// </summary>
        /// <param name="bptMaintainTask"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdPlanOrderEntity BptTaskToProdPo(BptMaintainTask bptMaintainTask);
        
        /// <summary>
        /// 技术部上传图纸
        /// </summary>
        /// <returns>返回保存文件全路径</returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileUploadReturnMessage UploadBlueprint(FileUploadMessage request);

        /// <summary>
        /// 技术部下载图纸
        /// </summary>
        /// <param name="fileName">全路径文件名</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileDownloadReturnMessage DownloadBlueprint(FileDownloadMessage request);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptMaintainTask SaveBptTask(string userNo,BptMaintainTask bptMaintainTask, List<BptBlueprintEntity> bpInfo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateBptMaintainTask(BptMaintainTask bptMaintainTask);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMasterEntity BptTaskToBom(BptMaintainTask bptMaintainTask);
        
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomTechnicEntity> BptBomToTechnic(BomMaintainMaster bomMaster,string userNo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string BptBomWfEnd(BomMaintainMaster bomMaster);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainTechnic AddBomTechnic(BomMaintainTechnic bomTechnic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainTechnic UpdateBomTechnic(BomMaintainTechnic bomTechnic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelBomTechnic(BomMaintainTechnic bomTechnic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainTechnic GetBomTechnicByKey(string bomTechnicId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainTechnic> GetBomTechnicAllListByCondition(BomQueryCondition queryCondition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBomTechnicAllDsByCondition(TechnicQueryCondition queryCondition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainTechnicItem AddBomTechnicItem(BomMaintainTechnicItem bomMaintainTechnicItem);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddBomTechnicItems(List<BomMaintainTechnicItem> bomMaintainTechnicItems);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainTechnicItem UpdateBomTechnicItem(BomMaintainTechnicItem bomMaintainTechnicItem);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateBomTechnicItems(List<BomMaintainTechnicItem> bomMaintainTechnicItems);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelBomTechnicItem(BomMaintainTechnicItem bomMaintainTechnicItem);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelBomTechnicItems(List<BomMaintainTechnicItem> bomMaintainTechnicItems);

        /// <summary>
        /// 根据工艺ID查询工艺明细
        /// </summary>
        /// <param name="bomTechnicId"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainTechnicItem> GetBomTechnicItem(string bomTechnicId);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bomTechnicId"></param>
        /// <returns>bi.*,t.TECHNIC_NAME </returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBomTechnicItemAllDsByTechnicId(string bomTechnicId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveBomTechnicItem(List<BomMaintainTechnicItem> bomMaintainTechnicItems);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainMaster GetBomMasterByKey(string bomMasterId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainMaster> GetBomMasterAllListByProductId(string productId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainMaster> GetAllActiveBomMaster();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBomAllDsByCondition(BomQueryCondition queryCondition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBomItemByMasterId(string bomMasterId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainMaster AddBomMaster(BomMaintainMaster bomMaintainMaster);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainMaster UpdateBomMaster(BomMaintainMaster bomMaintainMaster);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DelBomMaster(BomMaintainMaster bomMaintainMaster);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMasterEntity GetBomByKey(string bomId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool SaveBomItem(DataSet bomItems, DataSet delItems);

        /// <summary>
        /// 根据产品查询其物料清单（不包含自身）
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetDsBomItemByParentBom(BomMaintainMaster bm);

        /// <summary>
        /// 根据产品，查询工艺
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainTechnicItem> GetBomMTIAllListByProductId(string productId);

        /// <summary>
        /// 根据BOM ID，查询包括成品的物料清单
        /// </summary>
        /// <param name="masterId"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBomAllDsByMasterId(string bomMasterId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTOString GetBomMaxVersion(string productId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptBlueprintEntity GetBlueprintByKey(string id);

        ///// <summary>
        ///// 根据BOM明细ID，查询原材料
        ///// </summary>
        ///// <param name="bomItemId"></param>
        ///// <returns></returns>
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //DataSet GetBomItemMaterialAllDs(string bomItemId);


        ///// <summary>
        ///// 删除旧的物料清单原料，保存新的
        ///// </summary>
        ///// <param name="bomItemMaterials"></param>
        ///// <returns></returns>
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? SaveBomItemMaterials(DataSet bomItemMaterials);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetBlueprintByProductId(string productId);



        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetAllProductBlueprint();



        #region  工序
        //-----------------------工序--------------------------------------------------
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdTechnicAll();


        //查询工艺路线用料
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomTechnicItemMtrlEntity> GetBomTechnicItemMtrlByTechnicId(string bomTechnicId);

        //查询工序用料
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomTechnicItemMtrlEntity> GetBomTechnicItemMtrlByTechnicItemId(string bomTechnicItemId);

        //保存工艺路线用料
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveBomTechnicItemMtrl(List<BomTechnicItemMtrlEntity> bomTechnicItemMtrls);


        //删除工艺路线
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DeleteBomTechnicAndDetail(BomMaintainTechnic bomTechnic);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BptBlueprintEntity> GetBlueprintAllListByTaskId(string taskId);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainTechnic> AddBomTechnicList(List<BomMaintainTechnic> bomTechnic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainTechnic> UpdateBomTechnicList(List<BomMaintainTechnic> bomTechnic);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<BomMaintainTechnic> GetBomTechnicByLogicNo(string LogicNo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BomMaintainTechnicItem GetBomTechnicItemByKey(string technicItemId);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string AddProdTechnic(ProdTechnicEntity entity);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateProdTechnic(ProdTechnicEntity entity);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string DeleteProdTechnic(string id);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string CheckProdTechnicUsed(ProdTechnicEntity entity);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdTechnicEntity GetProdTechnicByKey(string id);
        
        #endregion


        #region 图纸变更
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTODataTable GetBptBluePrintChangesByCondition(BptBlueprintChangesEntity condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTOBool DeleteBptBluePrintChanges(BptBlueprintChangesEntity entity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTOBool InsertBptBluePrintChangesAndItems(BptBlueprintChangesEntity entity, List<BptBlueprintChangesItemEntity> items);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTOBool UpdateBptBluePrintChanges(BptBlueprintChangesEntity entity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTOBool UpdateBptBluePrintChangesAndItems(BptBlueprintChangesEntity entity, List<BptBlueprintChangesItemEntity> items);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTODataTable GetBptBluePrintChangesItemsByCondition(BptBlueprintChangesEntity condition);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptTaskEntity BptBlueprintChangeToTask(BptBlueprintChangesEntity bptMaintainApp,int days);

        #endregion

        #region  技术申请
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptMaintainApp GetBptMaintainAppByCondition(BptMaintainApp bptAppEntity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        BptMaintainTask GetBptMaintainTaskByCondition(BptMaintainTask bptTaskEntity);
        #endregion

    }
    
}
